<?php
session_start();
ob_start();

require_once("../conf/config.php"); 
require_once("../conf/database.php");
require_once("../conf/tools.php");
require_once("../includes/session.php");

$modeReport=$_REQUEST["rp_mode"];

if($modeReport==2012)
$strQuery = "SELECT date_submitted,membership_no,firstname,lastname,current_address,gender,profession,skills,yr_it,yr_gyan,email,country,telephone,fax,centre_incharge,centre_name,centre_zone,centre_email,centre_telephone,spiritual_service,meeting_purpose,involved,interested,last_attended_info,profile_status,resume_status,serving_remarks,interest_remarks,mem_id FROM bkitc_retreat where rec_status=1 and date_submitted<='2012-04-01' order by date_submitted desc";
else
	$strQuery = "SELECT date_submitted,membership_no,firstname,lastname,current_address,gender,profession,skills,yr_it,yr_gyan,email,country,telephone,fax,centre_incharge,centre_name,centre_zone,centre_email,centre_telephone,spiritual_service,meeting_purpose,involved,interested,last_attended_info,profile_status,resume_status,serving_remarks,interest_remarks,mem_id FROM bkitc_retreat where rec_status=1  and date_submitted>='2012-09-01' order by date_submitted desc";


$result=mysql_query($strQuery);
	$i = 0;


if($_REQUEST["export"]==1){
$file_type = "vnd.ms-excel";
$file_ending = "xls";

header("Content-Type: application/$file_type");
header("Content-Disposition: attachment; filename=Retreat_2012_List.$file_ending");
header("Pragma: no-cache");
header("Expires: 0");
genTable($result);
exit;
}
else{
if($_REQUEST["del"]==1){

$memIds=$_GET["memid"];
qry_data("update bkitc_retreat set rec_status=0 where mem_id in (".$memIds.")");
$result=mysql_query($strQuery);

}
$page_title="ITC Retreat 2012 - List";
include("includes/header.php");
?>
<br/>
<a href='?export=1'>Export to Excel</a> |  <a href='javascript:void(0);' onclick="deleteSelected()">Delete Selected</a> 
<br/>
<br/>

<div class=div style="overflow:auto;min-height:400px;width:900px;align:left;border:1px solid #000;" border=1 >
	<?=genTable($result)?>
</div>

<script>

function deleteSelected(){
memList="";

$$(".retreat_mem").each(function(vItem){

if(vItem.checked){

if(memList!="")
	memList= memList + "," +  vItem.value ;
else
	memList= vItem.value ;

}


});

location.href="?del=1&memid=" + memList;

}

</script>


<?php
include("includes/footer.php");
?>
<? } ?>
<?function genTable($result){?>

<table class="table_panel" cellpadding="6">
	<tr class="grey_bg">
	
	<? 
		if($_REQUEST["export"]!=1){
			echo "<th><b>Select</b></th>";
		}
		while ($i < mysql_num_fields($result)) 
		{
			$meta = mysql_fetch_field($result);
			echo "<th><b>". $meta->name."</b></th>";
			$i++;
		}
		
	?>
	
	</tr>
	<?

	while ($rs=mysql_fetch_array($result)) 
		{ 
			echo "<tr class='grey_bg'>";

			for($j=0;$j<$i;$j++){
			
			if($_REQUEST["export"]!=1){
				if($j==0) echo "<td><input class=retreat_mem type=checkbox value=".$rs['mem_id']."></td>";
			}
			 echo "<td>".$rs[$j]."</td>";
			 }
			echo "</tr>";
		}
		
	?>
	

</table>

<?}?>
